﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XingLucifer.IBase.Enums;

namespace XingLucifer.IBase
{
    public interface ICommunication
    {
        EndianTypes EndianType { get; }
        /// <summary>
        /// 设备IP或串口
        /// </summary>
        string IP { get; }
        /// <summary>
        /// 端口或波特率
        /// </summary>
        int Port { get; }
        /// <summary>
        /// 任务类型
        /// </summary>
        TaskTypes TaskType { get; }
        /// <summary>
        /// 服务名
        /// </summary>
        string ServiceName { get; }
        /// <summary>
        /// 设备类型
        /// </summary>
        Enums.DeviceTypes DeviceType { get; }
        /// <summary>
        /// 索引
        /// </summary>
        int Index { get; }
        /// <summary>
        /// 超时时间
        /// </summary>
        int Timeout { get; set; }
        /// <summary>
        /// 掉线回调委托
        /// </summary>
        Func<ICommunication, int, string, int, Enums.DeviceTypes, TaskTypes, string, CancellationTokenSource, bool> ReconnectDisconnection { get; set; }

        bool Write(byte[] bytes);
        byte[] Read(int length);
        string Read();
        public Dictionary<string, string> SendAndReceive(Dictionary<string, string> keyValuePairs);
        byte[] SendToRead(byte[] bytes, int count);
        bool Open();
        void Close();
        void SetProtocol(IProtocol protocol);

        int Receive(byte[] buffer);
    }
}
